import { get, post } from '@/utils/axios.js'



// 根据分类ID获取商品列表
export const getProductsByCategory = (categoryId, params) => get(`/api/product/list/${categoryId}`, params)

// 获取商品详情
export const getProductDetail = (productId) => get(`/api/product/detail/${productId}`)

// 获取完整商品详情（包含图片、单位、属性）
export const getProductFullDetail = (productId) => get(`/api/product/detail/full/${productId}`)

// 新增商品
export const addProduct = (data) => post('/api/product/add', data)

// 更新商品
export const updateProduct = (data) => post('/api/product/update', data)

// 删除商品
export const deleteProduct = (productId) => post('/api/product/delete', { id: productId })

// 更新商品状态
export const updateProductStatus = (productId, status) => post(`/api/product/${status === 1 ? 'on' : 'off'}/${productId}`)



// 商品属性相关API
// 获取属性列表
export const getAttributeList = (params) => get('/api/product/attribute/list', params)

// 获取属性详情
export const getAttributeDetail = (attrId) => get(`/api/product/attribute/detail/${attrId}`)

// 新增属性
export const addAttribute = (data) => post('/api/product/attribute/add', data)

// 更新属性
export const updateAttribute = (data) => post('/api/product/attribute/update', data)

// 删除属性
export const deleteAttribute = (attrId) => post('/api/product/attribute/delete', { id: attrId })

// 获取属性值列表
export const getAttributeValueList = (attrId) => get(`/api/product/attribute/values/${attrId}`)

// 新增属性值
export const addAttributeValue = (data) => post('/api/product/attribute/value/add', data)

// 更新属性值
export const updateAttributeValue = (data) => post('/api/product/attribute/value/update', data)

// 删除属性值
export const deleteAttributeValue = (valueId) => post('/api/product/attribute/value/delete', { id: valueId })

// 商品条码相关API
// 获取条码列表
export const getBarcodeList = (params) => get('/api/product/barcode/list', params)

// 分页获取条码列表
export const getBarcodeListPage = (params) => get('/api/product/barcode/listPage', params)

// 获取条码详情
export const getBarcodeDetail = (barcodeId) => get(`/api/product/barcode/detail/${barcodeId}`)

// 新增条码
export const addBarcode = (data) => post('/api/product/barcode/add', data)

// 更新条码
export const updateBarcode = (data) => post('/api/product/barcode/update', data)

// 删除条码
export const deleteBarcode = (barcodeId) => post(`/api/product/barcode/delete/${barcodeId}`)

// 批量删除条码
export const deleteBarcodes = (ids) => post('/api/product/barcode/batchDelete', ids)

// 更新条码状态
export const updateBarcodeStatus = (barcodeId, status) => post('/api/product/barcode/updateStatus', { id: barcodeId, status })

// 生成条码图片
export const generateBarcodeImage = (barcodeId, width = 300, height = 100) => 
  `/api/product/barcode/generateImage/${barcodeId}?width=${width}&height=${height}`

// 根据内容生成条码图片
export const generateBarcodeImageByContent = (content, barcodeType, width = 300, height = 100) => 
  `/api/product/barcode/generateImageByContent?content=${encodeURIComponent(content)}&barcodeType=${barcodeType}&width=${width}&height=${height}`

// 获取所有商品列表
export const getAllProducts = (productName) => get('/api/product/all', { productName })

// 获取所有单位列表
export const getAllUnits = () => get('/api/unit/list')

// 单位管理相关API
// 获取单位列表
export const getUnitList = (params) => get('/api/unit/list', params)

// 分页获取单位列表
export const getUnitListPage = (params) => get('/api/unit/listPage', params)

// 获取单位详情
export const getUnitDetail = (unitId) => get(`/api/unit/detail/${unitId}`)

// 新增单位
export const addUnit = (data) => post('/api/unit/add', data)

// 更新单位
export const updateUnit = (data) => post('/api/unit/update', data)

// 删除单位
export const deleteUnit = (unitId) => post(`/api/unit/delete/${unitId}`)

// 批量删除单位
export const deleteUnits = (ids) => post('/api/unit/batchDelete', ids)

// 更新单位状态
export const updateUnitStatus = (unitId, status) => post('/api/unit/updateStatus', { id: unitId, status })

// 商品分类相关API
// 获取分类列表
export const getCategoryList = (params) => get('/api/product/category/list', params)
// 分页获取分类列表
export const getCategoryListPage = (params) => get('/api/product/category/listPage', params)
// 获取分类详情
export const getCategoryDetail = (categoryId) => get(`/api/product/category/detail/${categoryId}`)
// 新增分类
export const addCategory = (data) => post('/api/product/category/add', data)
// 更新分类
export const updateCategory = (data) => post('/api/product/category/update', data)
// 删除分类
export const deleteCategory = (categoryId) => post(`/api/product/category/delete/${categoryId}`)
// 批量删除分类
export const deleteCategories = (ids) => post('/api/product/category/batchDelete', ids)
// 更新分类状态
export const updateCategoryStatus = (categoryId, status) => post('/api/product/category/updateStatus', { id: categoryId, status })
// 获取分类树
export const getCategoryTree = () => get('/api/product/category/tree')
// 获取所有分类列表
export const getAllCategories = () => get('/api/product/category/all')